﻿using System;
namespace AEM.Data.BLL.Actions
{
    public static class StatusPoints
    {
        static StatusPoints()//构造函数
        {
            AddStatusPoints = doAddStatusPoints;
            ModifiyStatusPoints = doModifiyStatusPoints;
            DeleteStatusPoints = doDeleteStatusPoints;
            SelectStatusPoints = doSelectStatusPoints;
            ImportTypeLib = doImportTypeLib;
            AddTypeLib = doAddTypeLib;
            ModifiyTypeLib = doModifiyTypeLib;
            DeleteTypeLib = doDeleteTypeLib;
            SelectTypeLib = doSelectTypeLib;
        }

        #region  函数体
        private static AddStatusPointsResult doAddStatusPoints(Model.StatusPoints args)
        {
            if (null == args) return AddStatusPointsResult.StatusPointsIsNull;
            Model.StatusPoints model = DAL.StatusPoints.Select(
                " StatusByte='" + args.StatusByte + "' AND StatusBit='" + args.StatusBit
                + "' AND LiftStatusNum=" + args.LiftStatusNum);
            if (null != model) return AddStatusPointsResult.StatusPointsIsExist;
            bool ret = DAL.StatusPoints.Add(args);
            if (ret)
                return AddStatusPointsResult.Ok;
            else
                return AddStatusPointsResult.Error;
        }
        private static ModifiyStatusPointsResult doModifiyStatusPoints(Model.StatusPoints args)
        {
            if (null == args) return ModifiyStatusPointsResult.StatusPointsIsNull;
            Model.StatusPoints model = DAL.StatusPoints.Select(" ID=" + args.ID);
            if (null == model) return ModifiyStatusPointsResult.StatusPointsIsNotExist;
            model = null;
            model = DAL.StatusPoints.Select(
               " StatusByte='" + args.StatusByte + "' AND StatusBit='" + args.StatusBit
               + "' AND LiftStatusNum=" + args.LiftStatusNum);
            if (null != model) return ModifiyStatusPointsResult.StatusPointsIsExist;
            bool ret = DAL.StatusPoints.Update(args);
            if (ret)
                return ModifiyStatusPointsResult.OK;
            else
                return ModifiyStatusPointsResult.Error;
        }
        private static DeleteStatusPointsResult doDeleteStatusPoints(int id)
        {
            Model.StatusPoints model = DAL.StatusPoints.Select("ID=" + id);
            if (null == model) return DeleteStatusPointsResult.StatusPointsIsNotExist;
            bool ret = DAL.StatusPoints.Delete(id);
            return DeleteStatusPointsResult.OK;
        }

        private static Model.StatusPoints doSelectStatusPoints(string byt, string bit, int status)
        {
            Model.StatusPoints model = DAL.StatusPoints.Select(
                " StatusByte='" + byt + "' AND StatusBit='" + bit
                + "' AND LiftStatusNum=" + status);
            if (null != model)
                return model;
            return null;
        }

        private static AddTypeLibResult doImportTypeLib(Model.TypeLib args)
        {
            if (null == args) return AddTypeLibResult.TypeLibIsNull;
            Model.TypeLib model = DAL.TypeLib.Select("TypeLibNum", args.TypeLibNum);
            if (null != model)
                doModifiyTypeLib(args);
            else
            {
                bool ret = DAL.TypeLib.Add(args);
            }

            return AddTypeLibResult.OK;
        }
        private static AddTypeLibResult doAddTypeLib(Model.TypeLib args)
        {
            if (null == args) return AddTypeLibResult.TypeLibIsNull;
            Model.TypeLib model = DAL.TypeLib.Select("TypeLibNum", args.TypeLibNum);
            if (null != model)
            {
                return AddTypeLibResult.TypeLibIDIsExist;
                //model.LiftType = args.LiftType;
                //model.StatusPoints = args.StatusPoints;
                //DAL.TypeLib.Update(model);
            }
            else
            {
                DAL.TypeLib.Add(args);
            }
            return AddTypeLibResult.OK;
        }
        private static ModifiyTypeLibResult doModifiyTypeLib(Model.TypeLib args)
        {
            if (null == args) return ModifiyTypeLibResult.TypeLibIsNull;
            Model.TypeLib model = DAL.TypeLib.Select("TypeLibNum", args.TypeLibNum);
            if (null != model)
            {
                if (model.ID != args.ID) return ModifiyTypeLibResult.TypeLibIDIsExist;
            }
            else
            {
                model = DAL.TypeLib.Select(args.ID);
                if (null == model) return ModifiyTypeLibResult.TypeLibIsNotExist;
            }

            if (null != model)
            {
                DAL.TypeLib.Update(args);
            }
            return ModifiyTypeLibResult.OK;

        }
        private static DeleteTypeLibResult doDeleteTypeLib(int id)
        {
            Model.TypeLib model = DAL.TypeLib.Select(id);
            if (null == model) return DeleteTypeLibResult.TypeLibIsNotExist;
            bool ret = DAL.TypeLib.Delete(id);
            return DeleteTypeLibResult.OK;
        }
        private static Model.TypeLib doSelectTypeLib(string tlNum)
        {
            return DAL.TypeLib.Select("TypeLibNum", tlNum);
        }
        #endregion 函数体

        #region 函数定义
        public static Func<Model.StatusPoints, AddStatusPointsResult> AddStatusPoints;
        /// <summary>
        /// 修改状态点信息
        /// </summary>
        public static Func<Model.StatusPoints, ModifiyStatusPointsResult> ModifiyStatusPoints;
        public static Func<int, DeleteStatusPointsResult> DeleteStatusPoints;
        public static Func<string, string, int, Model.StatusPoints> SelectStatusPoints;
        public static Func<Model.TypeLib, AddTypeLibResult> ImportTypeLib;

        public static Func<Model.TypeLib, AddTypeLibResult> AddTypeLib;
        public static Func<Model.TypeLib, ModifiyTypeLibResult> ModifiyTypeLib;
        public static Func<int, DeleteTypeLibResult> DeleteTypeLib;
        public static Func<string, Model.TypeLib> SelectTypeLib;

        #endregion 函数定义

        #region 状态返回值定义
        public enum AddStatusPointsResult
        {
            /// <summary>
            /// 添加成功
            /// </summary>
            Ok,
            /// <summary>
            /// 状态点已存在
            /// </summary>
            StatusPointsIsExist,
            /// <summary>
            /// 传入信息为NULL
            /// </summary>
            StatusPointsIsNull,
            Error
        }
        public enum ModifiyStatusPointsResult
        {
            /// <summary>
            /// 修改成功
            /// </summary>
            OK,
            /// <summary>
            /// 预修改状态点不存在
            /// </summary>
            StatusPointsIsNotExist,
            /// <summary>
            /// 状态点重复
            /// </summary>
            StatusPointsIsExist,
            /// <summary>
            /// 传入信息为NULL
            /// </summary>
            StatusPointsIsNull,
            Error
        }
        public enum DeleteStatusPointsResult
        {
            OK,
            /// <summary>
            /// 预删除状态点不存在
            /// </summary>
            StatusPointsIsNotExist
        }

        public enum AddTypeLibResult
        {
            OK,
            TypeLibIsNull,
            TypeLibIsExist,
            TypeLibIDIsExist
        }

        public enum ModifiyTypeLibResult
        {
            OK,
            TypeLibIsNull,
            TypeLibIsNotExist,
            TypeLibIDIsExist
        }

        public enum DeleteTypeLibResult
        {
            OK,
            TypeLibIsNotExist
        }
        #endregion 状态返回值定义

    }
}
